// 部门管理, 提交申请
import  Vue  from 'vue'
import {store} from '@/store/index'
import {auditKind, dataOperation} from '@/components/ivew_conf/auditing/auditing_type_conf'

const vueObj:any = new Vue()

const conf = {
    title: "提交申请",
    icon: 'icon-share',
    fn (){

        let organizationStore = store['state']['organizationStore']
        let type = organizationStore['currentType'];
        let action = organizationStore['currentAction'];
        let data = organizationStore['currentLoadFormData'];
        
        let reqMap = {
            company: 'post/departments/id',
            department: 'post/departments/id',
            personal: 'post/users/id'
        };

        let kind:number = 0

        Object.keys(auditKind).forEach(num =>{

            if(auditKind[num]['key'] === type){
                kind = parseInt(num)
            }

        })
       
        let map = {

            edit: 'update',
            create: 'creat',
            
        }

        Object.keys(dataOperation).forEach(num =>{

            if(dataOperation[num]['key'] ===  map[action]){
                action = parseInt(num)
            }
            
        })

        
        store.dispatch('request', {

            url: reqMap[type],
            data: {
                kind,
                data,
                action,
                notes: ''

            }
            
        }).then(success=>{

            if(success){

                vueObj.$Notice.success({
                    title: '申请成功，等待审核'
                })

                // 关闭表单
                setTimeout(()=>{
                    store.commit('organizationStore/foldingLayerSwitch')
                }, 500)
                
                
            }
            
        })
        
    }
}

export default conf